const one_day = 1000 * 60 * 60 * 24;
const one_house = 1000 * 60 * 60;
const one_min = 1000 * 60;
const one_sec = 1000;

function format_date(date){
  if(!date) throw new Error("data is required");  
  const now_data = +new Date();
  const difference = now_data - date;
  let difference_time;
  const difference_day = parseInt(difference / one_day);
  difference_time = difference-difference_day*one_day;
  const difference_house = parseInt(difference_time / one_house);
  difference_time = difference_time-difference_house*one_house;
  const difference_min = parseInt(difference_time / one_min);
  difference_time = difference_time-difference_min*one_min;
  const difference_sec = parseInt(difference_time / one_sec);
  let time = {difference_day,difference_house,difference_min,difference_sec}
  if(!difference_day){ // 小于1d
    if(!difference_house){// 小于1h
      if(!difference_min){ // 小于1m
        return {time,msg:"刚刚"}
      }else{
        return {time,msg:`${difference_min}分前`}
      }
    }else{
      return {time,msg:`${difference_house}小时前`}
    }
  }else{
    return {time,msg:`${difference_day}天前`}
  }
}